<template>
  <div>
    <el-table :data="x" v-for="x in tableData" :key="x.uid" style="width: 100%">
      <el-table-column type="selection" width="55" align="center">
      </el-table-column>
      <el-table-column label="菜名" width="180" align="center">
        <template slot-scope="scope">
          <el-popover placement="top">
            <!-- <p>详情: {{ scope.row.detail }}</p> -->
            <!-- <p>密码: {{ scope.row.upwd }}</p> -->
            <div slot="reference" class="name-wrapper">
              <el-tag size="medium">{{ scope.row.name }}</el-tag>
            </div>
          </el-popover>
        </template>
      </el-table-column>

      <el-table-column label="图片" width="180" align="center">
        <template slot-scope="scope">
          <!-- <i class="el-icon-time"></i> -->
          <!-- <span style="margin-left: 10px">{{ scope.row.name }}</span> -->
          <div class="imgbox">
            <img :src="`https://ichf.cn/${scope.row.image}`" alt="" />
          </div>
        </template>
      </el-table-column>
      <el-table-column label="品类" width="180" align="center">
        <template slot-scope="scope">
          <!-- <i class="el-icon-time"></i> -->
          <span style="margin-left: 10px">{{ scope.row.kind }}</span>
        </template>
      </el-table-column>
      <el-table-column label="地区" width="180" align="center">
        <template slot-scope="scope">
          <!-- <i class="el-icon-time"></i> -->
          <span style="margin-left: 10px">{{ scope.row.area }}</span>
        </template>
      </el-table-column>
      <el-table-column label="详情" width="540" align="center">
        <template slot-scope="scope">
          <!-- <i class="el-icon-time"></i> -->
          <span
            :title="scope.row.detail"
            style="
              margin-left: 10px;
              overflow: hidden;
              text-overflow: ellipsis;
              white-space: nowrap;
              height: 100px;
            "
            >{{ scope.row.detail }}</span
          >
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template>
          <el-button size="mini" @click="dialogVisible = true">编辑</el-button>
          <el-button
            size="mini"
            type="danger"
            @click="centerDialogVisible = true"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      @current-change="handleCurrentChange"
      :current-page="pagenum"
      :page-size="pagesize"
      layout="prev, pager, next"
      :total="total"
    >
    </el-pagination>
    <div>
      <el-dialog title="提示" :visible.sync="dialogVisible" width="30%">
        <span>这是一段信息</span>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="dialogVisible = false"
            >确 定</el-button
          >
        </span>
      </el-dialog>
      <el-dialog
        title="提示"
        :visible.sync="centerDialogVisible"
        width="30%"
        center
      >
        <span>你确定要删除吗？</span>
        <span slot="footer" class="dialog-footer">
          <el-button @click="centerDialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="centerDialogVisible = false"
            >确 定</el-button
          >
        </span>
      </el-dialog>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [],
      dialogVisible: false,
      centerDialogVisible: false,
      total: 0,

      query: [],
      // 当前页数
      pagenum: 1,
      // 显示一页多少条数据
      pagesize: 6,
    };
  },
  methods: {
    goData() {
      let url = `http://127.0.0.1:3000/data/index/page?page=${this.pagenum}&size=${this.pagesize}`;
      console.log(url);
      this.axios.get(url).then((res) => {
        this.tableData.splice(0, this.tableData.length);
        this.tableData.push(res.data.data);
        console.log(this.tableData);
      });
    },
    getData() {
      let url = `http://127.0.0.1:3000/data/index/search_taste`;
      console.log(url);
      this.axios.get(url).then((res) => {
        this.total = res.data.data.length;
        console.log(this.total);
      });
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      this.pagenum = val;
      console.log(this.pagenum);
      // console.log(`当前页: ${val}`);
    },
  },
  watch: {
    pagenum() {
      this.goData();
    },
  },
  mounted() {
    this.getData();
    this.goData();
  },
};
</script>

<style lang="scss" scoped>
.imgbox {
  width: 90%;
  height: 100px;
  overflow: hidden;
  border-radius: 10px;
  img {
    width: 100%;
    height: 100%;
    transition: all 0.5s;

    &:hover {
      transition: all 0.5s;
      transform: scale(1.2);
    }
  }
}
</style>
